package main

import (
	"fmt"
	"net/http"
	"./view"
)

func main()  {

	v := view.NewView("./templates")

	v.AddFunc("myfunc", func(name string) string {
		return "myfunc value: " + name
	})

	// 打包template文件到bin文件里面
	// go get -u github.com/shuLhan/go-bindata
	// go-bindata ./templates/...
	// go build
	// ./app
	// v.BinData(Asset, AssetNames)

	err := v.Layout("layout").Load()
	if err != nil {
		panic(err)
	}

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		err := v.Render(w, "page", "data test")
		fmt.Println(err)
	})

	fmt.Println("start http server 127.0.0.1:8000")

	err = http.ListenAndServe(":8000", nil)
	if err != nil {
		panic(err)
	}
}
